﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;
using ReBasic.Algorithm;
using ReBasic.Helper;
using ReBasic.Database;
using ReBasic.Model;

namespace ReBasic
{
    public partial class MainFrame : Form
    {
        #region Helper/Extracter/Delegate Definition

        public delegate void TripleHandler(int va, int vb, int perc);
        public delegate void InfoHandler(string info, bool isOver);
        public delegate void ProcessHandler(int perc);

        SentenceExtractor se;
        AttrEntityExtractor aee;
        RelationshipExtractor re;
        DictHelper dh;
        StringHelper sh;
        TermExtractor te;
        SeedPairExtractor spe;
        WikiFormatHelper wfh;
        Thread t;
        Stopwatch sw;
        MsraFormatHelper mfh;

        #endregion

        //public const string DataPath = @"G:\RE_DATA\";
        public const string DataPath = @"F:\Relationship_Extraction\ProcessData\";
        public const string SentPath = DataPath + "Sent.txt";
        public const string TermPath = DataPath + "Term.txt";
        public const string ChunkPath = DataPath + "Chunk.txt";
        public const string CorpusPath = DataPath + "Corpus.txt";
        public const string SentDsPath = DataPath + "Sent_ds.txt";
        public const string SubConPath = DataPath + "SubConDict.txt";
        public const string SupConPath = DataPath + "SupConDict.txt";
        public const string AttrEntityPath = DataPath + "AttrEntity.txt";
        public const string SelAttrEntityPath = DataPath + "SelAttrEntity.txt";
        public const string TriplePath = DataPath + "Triple_hrt.txt";
        public const string SeedPath = DataPath + "Seed.txt";
        public const string SeedTmpPath = DataPath + "SeedTmp.txt";
        public const string MsraPath = DataPath + "action_0_1_combined_20.sen";

        public const int TotalSent = 84122810;                      //Msra 0_0 + 0_1
        //public const int TotalSent = 74285292;                  //Wikipedia/0902, split up Stanford Parser
        //public const int TotalSent = 43300475;                  //Msra 0_0
        //public const int TotalSent = 40822335;                    //Msra 0_1
        //public const int TotalSent = 76963469;                //Wikipedia/Kaiqi, split up by Stanford Parser
        //public const int TotalSent = 73133865;                //Wikipedia/Kaiqi, split up Naive, and without "Poland" series.
        //public const int TotalSent = 39589451;                //Wikipedia, without "Poland" series.
        //public const int TotalSent = 39709717;                //Wikipedia
        //public const int TotalSent = 139567724;               //Full Wikimedia Old
        public const int TotalSupConcept = 2402435;
        public const int TotalSubConcept = 8034922;
        public const int TotalFrequency = 25431182;
        public const int TotalDbItems = 15816246;

        public MainFrame()
        {
            InitializeComponent();
            #region Generate Helper/Extracter... And load event handler
            se = new SentenceExtractor();
            aee = new AttrEntityExtractor();
            re = new RelationshipExtractor();
            dh = new DictHelper();
            te = new TermExtractor();
            sh = new StringHelper();
            spe = new SeedPairExtractor();
            wfh = new WikiFormatHelper();
            sw = new Stopwatch();
            mfh = new MsraFormatHelper();
            ProBase.ProcessEvent += new TripleHandler(ProBase_ProcessEvent);
            ProBase.StateEvent += new InfoHandler(StateEvent);
            re.ProcessEvent += new TripleHandler(re_ProcessEvent);
            re.StateEvent += new InfoHandler(StateEvent);
            re.DetailProcessEvent += new ProcessHandler(DetailProcessEvent);
            se.ProcessEvent += new TripleHandler(se_ProcessEvent);
            se.StateEvent += new InfoHandler(StateEvent);
            aee.ProcessEvent += new TripleHandler(aee_ProcessEvent);
            aee.StateEvent += new InfoHandler(StateEvent);
            dh.ProcessEvent += new TripleHandler(dh_ProcessEvent);
            dh.StateEvent += new InfoHandler(StateEvent);
            te.ProcessEvent += new TripleHandler(te_ProcessEvent);
            te.StateEvent += new InfoHandler(StateEvent);
            spe.ProcessEvent += new TripleHandler(spe_ProcessEvent);
            spe.StateEvent += new InfoHandler(StateEvent);
            spe.DetailProcessEvent += new ProcessHandler(DetailProcessEvent);
            wfh.ProcessEvent += new TripleHandler(wfh_ProcessEvent);
            wfh.StateEvent += new InfoHandler(StateEvent);
            mfh.ProcessEvent += new TripleHandler(mfh_ProcessEvent);
            mfh.StateEvent += new InfoHandler(StateEvent);
            sh.StateEvent += new InfoHandler(StateEvent);
            sh.DetailProcessEvent +=new ProcessHandler(DetailProcessEvent);
            #endregion
        }

        private void MainFrame_Load(object sender, EventArgs e)
        {   
            TermExtractor.InitStopWord();
            //Thread t = new Thread(new ThreadStart(() =>
            //{
            //    ProBase.GenerateProbase();
            //    re.Work(ProBase.SubConDict);
            //    spe.Work(DataPath, "Triple_hrt.txt", ProBase.SupConDict);
            //}));
            //t.Start();
            //sw.Reset();
            //sw.Start();
        }

        #region EventHanlder Sets

        void StateEvent(string info, bool isOver)
        {
            this.Invoke(new Action(() =>
            {
                tbShow.Text += (info + "\r\n");
                if (isOver)
                    pbShow.Value = 100;
            }));
        }

        void DetailProcessEvent(int perc)
        {
            this.Invoke(new Action(() =>
            {
                pbDetail.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void ProBase_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Items: " + va.ToString();
                tsslGen.Text = "Read items: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void aee_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Sentences: " + va.ToString();
                tsslGen.Text = "Attr-Ent Gen: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void se_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Sentences: " + va.ToString();
                tsslGen.Text = "TextPart: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void dh_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Items: " + va.ToString();
                tsslGen.Text = "Dist. SubConcepts: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void te_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Sentences: " + va.ToString();
                tsslGen.Text = "Terms: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void re_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
                {
                    tsslSent.Text = "Host entity: " + va.ToString();
                    tsslGen.Text = "Candidate terms: " + vb.ToString();
                    pbShow.Value = perc;
                    tsslTime.Text = "Time => " +
                        sw.Elapsed.Hours + ":" +
                        sw.Elapsed.Minutes + ":" +
                        sw.Elapsed.Seconds;
                }
            ));
        }

        void spe_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Super-concept: " + va.ToString();
                tsslGen.Text = "Current Concept: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }
            ));
        }

        void wfh_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Sentences: " + va.ToString();
                tsslGen.Text = "Sent_ds Gen: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        void mfh_ProcessEvent(int va, int vb, int perc)
        {
            this.Invoke(new Action(() =>
            {
                tsslSent.Text = "Sentences: " + va.ToString();
                tsslGen.Text = "Sentences: " + vb.ToString();
                pbShow.Value = perc;
                tsslTime.Text = "Time => " +
                    sw.Elapsed.Hours + ":" +
                    sw.Elapsed.Minutes + ":" +
                    sw.Elapsed.Seconds;
            }));
        }

        #endregion

        #region Data Part
        private void btnSent_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(se.GenerateSent));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnSentDs_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(se.GenerateSentDs));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnSubConDict_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(dh.GenerateSupDict));
            //t = new Thread(new ThreadStart(dh.GenerateSubDict));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnTermDs_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(() =>
                {
                    //dh.LoadSubConDict();
                    ProBase.GenerateProbase();
                    te.Work(ProBase.SubConDict);
                }
            ));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnAttrEnt_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(() =>
            {
                //dh.LoadSubConDict();
                aee.Work(ProBase.SubConDict);
            }
            ));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnStopSent_Click(object sender, EventArgs e)
        {
            try
            {
                sw.Stop();
                if (t != null)
                {
                    t.Abort();
                    t = null;
                }
                se.CloseFile(0);
            }
            catch (Exception ex)
            {
                tbShow.Text = ex.ToString();
            }
        }

        private void btnStopSentDs_Click(object sender, EventArgs e)
        {
            try
            {
                sw.Stop();
                if (t != null)
                {
                    t.Abort();
                    t = null;
                }
                se.CloseFile(1);
            }
            catch (Exception ex)
            {
                tbShow.Text = ex.ToString();
            }
        }

        private void btnStopSubSet_Click(object sender, EventArgs e)
        {
            try
            {
                sw.Stop();
                if (t != null)
                {
                    t.Abort();
                    t = null;
                }
                dh.CloseFile(0);
            }
            catch (Exception ex)
            {
                tbShow.Text = ex.ToString();
            }
        }

        private void btnStopTermDs_Click(object sender, EventArgs e)
        {
            try
            {
                sw.Stop();
                if (t != null)
                {
                    t.Abort();
                    t = null;
                }
                te.CloseFile(0);
            }
            catch (Exception ex)
            {
                tbShow.Text = ex.ToString();
            }
        }

        private void btnStopAttrEnt_Click(object sender, EventArgs e)
        {
            try
            {
                sw.Stop();
                if (t != null)
                {
                    t.Abort();
                    t = null;
                }
                aee.CloseFile();
            }
            catch (Exception ex)
            {
                tbShow.Text = ex.ToString();
            }
        }

        private void btnSplit_Click(object sender, EventArgs e)
        {
            string str = MainFrame.DataPath + tbSplit.Text;
            if (File.Exists(str))
            {
                int idx = str.LastIndexOf('\\');
                string fp = str.Substring(0, idx + 1);
                string fn = str.Substring(idx + 1);
                t = new Thread(new ThreadStart(() =>
                    {
                        sh.SplitTripleSet(fp, fn);
                    }
                ));
                t.Start();
            }
            else
                MessageBox.Show(str + " is not exist.");
        }

        private void btnPbSup_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(() =>
            {
                ProBase.GenerateProbase();
                string s = tbToClass.Text;
                if (!ProBase.SubConDict.ContainsKey(s))
                {
                    this.Invoke(new Action(() =>
                    {
                        tbShow.Text += "FIND NULL\r\n";
                    }));
                    return;
                }
                List<IndexRelation> ixrel = ProBaseInterface.FindTopInSub(s, 0);
                for (int i = 0; i < ixrel.Count; i++)
                {
                    string ret = ProBase.SupUhash[ixrel[i].sup_idx];
                    this.Invoke(new Action(() =>
                    {
                        tbShow.Text += ret + "\t" + ixrel[i].freq + "\r\n";
                    }));
                }
                if (ixrel.Count == 0)
                    this.Invoke(new Action(() =>
                    {
                        tbShow.Text += "FIND NULL\r\n";
                    }));
                this.Invoke(new Action(() =>
                {
                    tbShow.Text += "----------------------------\r\n";
                }));
            }));
            th.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnPbSub_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(() =>
            {
                ProBase.GenerateProbase();
                string s = tbToEntity.Text;
                if (!ProBase.SupConDict.ContainsKey(s))
                {
                    this.Invoke(new Action(() =>
                    {
                        tbShow.Text += "FIND NULL\r\n";
                    }));
                    return;
                }
                List<IndexRelation> ixrel = ProBaseInterface.FindTopInSup(s, 0);
                for (int i = 0; i < ixrel.Count; i++)
                {
                    string ret = ProBase.SubUhash[ixrel[i].sub_idx];
                    this.Invoke(new Action(() =>
                    {
                        tbShow.Text += ret + "\t" + ixrel[i].freq + "\r\n";
                    }));
                }
                if (ixrel.Count == 0)
                    this.Invoke(new Action(() =>
                    {
                        tbShow.Text += "FIND NULL\r\n";
                    }));
                this.Invoke(new Action(() =>
                {
                    tbShow.Text += "----------------------------\r\n";
                }));
            }));
            th.Start();
            sw.Reset();
            sw.Start();
        }

        #endregion

        #region RE Part
        
        private void btnDoAll_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(() =>
            {
                ProBase.GenerateProbase();
                re.Work(ProBase.SubConDict);
                spe.Work(MainFrame.TriplePath, ProBase.SupConDict, "Seed");
            }));
            th.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnRelExtract_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(() =>
                {
                    ProBase.GenerateProbase();
                    re.Work(ProBase.SubConDict);
                }
            ));
            th.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnPhase3_Click(object sender, EventArgs e)
        {
            string str, seedName;
            if (tbPhase3.Text == "")
            {
                str = MainFrame.TriplePath;
                seedName = "Seed";
            }
            else
            { 
                str = MainFrame.DataPath + "Triple_hrt_" + tbPhase3.Text + ".txt";
                seedName = "Seed_" + tbPhase3.Text;
            }
            if (File.Exists(str))
            {
                int idx = str.LastIndexOf('\\');
                string fp = str.Substring(0, idx + 1);
                string fn = str.Substring(idx + 1);
                Thread th = new Thread(new ThreadStart(() =>
                    {
                        ProBase.GenerateProbase();
                        spe.Work(str, ProBase.SupConDict, seedName);
                    }
                ));
                th.Start();
                sw.Reset();
                sw.Start();
            }
            else
            {
                MessageBox.Show(str + " is not exist.");
            }
        }

        private void btnCustomWork_Click(object sender, EventArgs e)
        {
            Thread t = new Thread(new ThreadStart(() =>
                {
                    mfh.Work();
                    ProBase.GenerateProbase();
                    te.Work(ProBase.SubConDict);
                }
            ));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        #endregion

        #region View Part

        private void btnClr_Click(object sender, EventArgs e)
        {
            tbShow.Text = "";
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            string FilePath = MainFrame.DataPath + tbPath.Text + ".txt";
            if (File.Exists(FilePath))
                tbShow.Text += ViewHelper.ViewFile(FilePath, false);
            else
                tbShow.Text += "File is not exist.\r\n";
        }

        private void btnViewRandom_Click(object sender, EventArgs e)
        {
            string FilePath = MainFrame.DataPath + tbPath.Text + ".txt";
            if (File.Exists(FilePath))
                tbShow.Text += ViewHelper.ViewFile(FilePath, true);
            else
                tbShow.Text += "File is not exist.\r\n";
        }

        #endregion

        #region Test Part

        private void btnCustomTest_Click(object sender, EventArgs e)
        {
            int cnt = 0;
            FileStream fsw = new FileStream(MainFrame.DataPath + "Chunk_seg1.txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fsw, Encoding.UTF8);

            FileStream fsr;
            StreamReader sr;
            fsr = new FileStream(MainFrame.DataPath + "Chunk_seg2.txt", FileMode.Open);
            sr = new StreamReader(fsr, Encoding.UTF8);
            while (!sr.EndOfStream)
            {
                sw.WriteLine(sr.ReadLine());
                cnt++;
            }
            sr.Close(); fsr.Close();

            fsr = new FileStream(MainFrame.DataPath + "Chunk_seg3.txt", FileMode.Open);
            sr = new StreamReader(fsr, Encoding.UTF8);
            while (!sr.EndOfStream)
            {
                sw.WriteLine(sr.ReadLine());
                cnt++;
            }
            sr.Close(); fsr.Close();

            sw.Close(); fsw.Close();
            MessageBox.Show("DONE " + cnt.ToString());
        }

        private void btnStat_Click(object sender, EventArgs e)
        {
            int cnt = 0;
            FileStream fs;
            StreamReader sr;
            int[] arr = new int[10];
            int err = 0;
            string[] range = {"1~1", "2~2", "3~3", "4~4", "5~5", "6~10", "11~50", "51~100",
                             "101~500", ">=501"};
            Thread t = new Thread(new ThreadStart(() =>
            {
                fs = new FileStream(TriplePath, FileMode.Open);
                sr = new StreamReader(fs, Encoding.UTF8);
                sr.ReadLine();
                while (!sr.EndOfStream)
                {
                    string str = sr.ReadLine();
                    string[] spt = str.Split('\t');
                    int tms = int.Parse(spt[3]), ht = int.Parse(spt[5]);
                    if (ht < tms) err++;
                    else
                    {
                        if (tms == 1) arr[0]++;
                        else if (tms == 2) arr[1]++;
                        else if (tms == 3) arr[2]++;
                        else if (tms == 4) arr[3]++;
                        else if (tms == 5) arr[4]++;
                        else if (tms <= 10) arr[5]++;
                        else if (tms <= 50) arr[6]++;
                        else if (tms <= 100) arr[7]++;
                        else if (tms <= 500) arr[8]++;
                        else arr[9]++;
                    }
                    if (++cnt % 10000 == 0)
                        spe_ProcessEvent(cnt, cnt, 0);
                }
                sr.Close();
                fs.Close();
                this.Invoke(new Action(() =>
                {
                    for (int i = 0; i < 10; i++)
                        tbShow.Text += range[i] + "\t" + arr[i].ToString() + "\r\n";
                    tbShow.Text += "Error\t" + err.ToString() + "\r\n";
                }));
            }));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnSearchOccur_Click(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(() =>
            {
                sh.SearchOccurrence(tbSearch1.Text,
                    tbSearch2.Text, tbSearch3.Text);
            }));
            th.Start();
            sw.Reset();
            sw.Start();
        }

        #endregion

        #region Wiki Part

        private void btnWikiSentDs_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(() =>
                {
                    wfh.Work(0);
                    ProBase.GenerateProbase();
                    te.Work(ProBase.SubConDict);
                }
            ));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnWikiSent_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(() =>
                {
                    wfh.Work(1);
                    //ProBase.GenerateProbase();
                    //te.Work(ProBase.SubConDict);
                }
            ));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnStopWikiSentDs_Click(object sender, EventArgs e)
        {
            try
            {
                sw.Stop();
                if (t != null)
                {
                    t.Abort();
                    t = null;
                }
                wfh.CloseFile(0);
            }
            catch (Exception ex)
            {
                tbShow.Text = ex.ToString();
            }
        }

        private void btnWikiSentNaive_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(() =>
            {
                wfh.Work(2);
            }
            ));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnMsraGen_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(mfh.Work));
            t.Start();
            sw.Reset();
            sw.Start();
            //int pos = 0;
            //string str = "(ROOT (S (PP (IN In) (NP (JJ other) (NNS words))) (, ,) (NP (PRP it)) (VP (MD wo) (RB n't) (VP (VB fit) (PP (IN without) (NP (NN modification))))) (. .)))";
            ////string str = "(ROOT (S (NP (PRP He)) (VP (VBZ is) (ADVP (RB also)) (NP (DT a) (JJ quick) (NN study)) (, ,) (S (VP (VBG devouring) (NP (NP (JJ new) (NNS technologies) (, ,) (NNS products) (CC and) (NNS markets)) (PP (IN in) (NP (JJ short) (NN order))))))) (. .)))";
            //TreeNode tr = mfh.generate_parse_tree(str, ref pos);
            //tvTest.Nodes.Clear();
            //tvTest.Nodes.Add(tr);
            //tvTest.ExpandAll();
            //tvTest.Update();
            //List<string> res = mfh.find_base_np(tr);
        }
        #endregion

        #region ProBase Part

        private void btnPbHash_Click(object sender, EventArgs e)
        {
            //t = new Thread(new ThreadStart(ProBase.Init_CreateHash));
            //t.Start();
            //sw.Reset();
            //sw.Start();
        }

        private void btnPbPool_Click(object sender, EventArgs e)
        {
            //t = new Thread(new ThreadStart(ProBase.Init_FillPool));
            //t.Start();
            //sw.Reset();
            //sw.Start();
        }

        private void btnPbFile_Click(object sender, EventArgs e)
        {
            //t = new Thread(new ThreadStart(ProBase.PrePare_MakeFile));
            //t.Start();
            //sw.Reset();
            //sw.Start();
        }

        private void btnPbFreq_Click(object sender, EventArgs e)
        {
            //t = new Thread(new ThreadStart(ProBase.Init_FillFreq));
            //t.Start();
            //sw.Reset();
            //sw.Start();
        }

        private void btnPbGen_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(ProBase.GenerateProbase));
            t.Start();
            sw.Reset();
            sw.Start();
        }

        private void btnPbSave_Click(object sender, EventArgs e)
        {

        }

        #endregion


    }
}
